#include "thekeypad.h"
//char thekeyboard_flag=0;

theKeypad::theKeypad(QWidget *parent) : QWidget(parent)
{
    this->setStyleSheet("QWidget{        background-color: rgb(0, 170, 255);/* 背景颜色 */}");
    this->setFixedSize(640,430);
//    for(int i=0;i<2;i++)//创建主屏幕显示的按键
//    {
    theBtn[0] = new QPushButton(this);
    theBtn[1] = new QPushButton(this);
//    }
    ui_init();
//    QVBoxLayout *layout = new QVBoxLayout;           //新建Layout
//    QLabel *label_1 = new QLabel;                    //新建QLabel
//    //设置字体、字号、加粗
//    //QFont ft("Microsoft YaHei", 12, 87);

//    label_1->setText(" Being reconstructed, Please wait.");

//    label_1->setAlignment(Qt::AlignCenter);         //设置文字上下左右居中

//    layout->addWidget(label_1);                     //将label添加到layout中

//    this->setLayout(layout);                   //将layout添加到QWidget
    qDebug()<<"123";
}
void theKeypad::ui_init()
{
    QFont font;
     //设置文字大小
     font.setPointSize(16);
    for(int i=0;i<2;i++)//创建主屏幕显示的按键
    {
//         theBtn[0] = new QPushButton(this);
         theBtn[0]->setStyleSheet("QPushButton{\
                                outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                                background-color: rgb(22, 11, 33);	    /* 背景颜色 */\
                                border-radius: 4px;		                 /* 按钮边框的圆角设置 */\
                                border-style: outset;\
                                border: 1px groove gray;\
                                padding:1px 4px;\
                                /* 按钮文本设置 */\
                                text-align:center ;			             /* 文本的位置 */\
                                font-size: 20px;\
                                color: #FFFFFF;			                 /* 文本颜色 */\
                           }"
          );
//    theBtn[i]->setGeometry(10+i*30,40,75,25);//0按键


//    switch (i)
//    {
//    case 0:
//      {
//        theBtn[0]->setGeometry(10,40,75,25);//0按键
//       theBtn[0]->setText(("0"));
//       break;
//      }
//    case 1:
//      {
//        theBtn[1]->setGeometry(80,40,75,25);//1按键
//        theBtn[1]->setText(("1"));
//        break;
//      }
//    case 2:
//      {
//        theBtn[2]->setGeometry(150,40,75,25);//2按键
//        theBtn[2]->setText(("2"));
//        break;
//      }
//    case 3:
//      {
//        theBtn[3]->setGeometry(220,40,75,25);//3按键
//        theBtn[3]->setText(("3"));
//            break;
//      }
//    case 4:
//      {
//            theBtn[4]->setGeometry(10,70,75,25);//4按键
//            theBtn[4]->setText(("4"));

//         break;
//      }
//    case 5:
//      {
//            theBtn[5]->setGeometry(80,70,75,25);//5按键
//            theBtn[5]->setText(("5"));

//        break;
//      }
//    case 6:
//      {
//        theBtn[6]->setGeometry(150,70,75,25);//6按键
//        theBtn[6]->setText(("6"));
//break;
//      }
//    case 7:
//      {
//        theBtn[7]->setGeometry(220,70,75,25);//7按键
//        theBtn[7]->setText(("7"));
//   break;
//      }
//    case 8:
//      {
//        theBtn[8]->setGeometry(10,100,75,25);//8按键
//        theBtn[8]->setText(("8"));
//      break;
//      }
//    case 9:
//      {
//        theBtn[9]->setGeometry(80,100,75,25);//9按键
//        theBtn[9]->setText(("9"));
//      break;
//      }
//    case 10:
//      {
//        theBtn[10]->setGeometry(150,70,42,25);//-按键
//        theBtn[10]->setText(tr("-"));
//break;
//      }
//    case 11:
//      {
//        theBtn[11]->setGeometry(197,70,42,25);//.按键
//        theBtn[11]->setText(tr("."));
//     break;
//      }
//    case 12:
//      {
//        theBtn[12]->setGeometry(240,70,43,25);//删除按键
//        theBtn[12]->setText(tr("×"));
//   break;
//      }
//    case 13:
//      {
//        theBtn[13]->setGeometry(10,10,150,25);//显示按键
//     break;
//      }
//    case 14:
//      {
//        theBtn[14]->setGeometry(120,10,75,25);//OK按键
//        theBtn[14]->setText(tr("OK"));
//break;
//      }
//    case 15:
//      {
//        theBtn[15]->setGeometry(220,10,75,25);//CanCel按键
//        theBtn[15]->setText(tr("CanCel"));
//            break;
//      }
//    }

//    BtnList.append(theBtn[i]);
    }

////      for(int i=0;i<BtnList.length();i++)
////    {
////        BtnList.at(i)->installEventFilter(this);
////        if(i<BtnList.length()-1)
////            setTabOrder(BtnList.at(i),BtnList.at(i+1));
////    }
////    theBtn[14]->setFocus();
}
void theKeypad::recive_otherdata(QString num)
{
//    theBtn[13]->setText(num);
}
void theKeypad::connect_init()
{
//    connect(theBtn[0],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"0");
//    });
//    connect(theBtn[1],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"1");
//    });
//     connect(theBtn[2],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"2");
//    });
//    connect(theBtn[3],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"3");
//    });
//    connect(theBtn[4],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"4");
//    });
//    connect(theBtn[5],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"5");
//    });
//    connect(theBtn[6],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"6");
//    });
//    connect(theBtn[7],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"7");
//    });
//    connect(theBtn[8],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"8");
//    });
//    connect(theBtn[9],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"9");
//    });
//    connect(theBtn[10],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+"-");
//    });
//    connect(theBtn[11],&QPushButton::clicked,[=](){
//        theBtn[13]->setText(theBtn[13]->text()+".");
//    });
//    connect(theBtn[12],&QPushButton::clicked,[=](){
//                QString text = theBtn[13]->text();
//                 theBtn[13]->setText(text.remove(text.length()-1,1));
//    });
//        connect(theBtn[14] ,&QPushButton::clicked,[=](){
//            if(theBtn[13]->text().length()>0)
//            {
//                NumKeyBoard= theBtn[13]->text();
//                emit changename2(NumKeyBoard);
//            }
//            else
//                NumKeyBoard = "NULL";
//            this->close();
//        });
//            connect(theBtn[15] ,&QPushButton::clicked,[=](){
//                NumKeyBoard = "NULL";
//                this->close();
//            });
}
//bool theKeypad::eventFilter(QObject *watched, QEvent *event)
//{
//    for(int i=0;i<BtnList.length();i++)
//        if(watched==BtnList.at(i))
//    {
//        if(event->type() == QEvent::KeyPress)
//        {
//           QKeyEvent *ev = (QKeyEvent *)event;
//           QPushButton *button = (QPushButton *)watched;
//           switch (ev->key())
//           {
//           case UP:
//             {
//               if(watched==theBtn[14] ||watched==theBtn[15])
//                   break;
//               else if(watched ==theBtn[0] || watched == theBtn[1]|| watched == theBtn[2])
//               {
//                   theBtn[14]->setFocus();
//                   break;
//               }
//               else if(watched==theBtn[3])
//               {
//                   theBtn[15]->setFocus();
//                   break;
//               }
//               else if(watched==theBtn[12])
//               {
//                   theBtn[7]->setFocus();
//                   break;
//               }
//               else
//               {
//                   focusPreviousChild();focusPreviousChild();focusPreviousChild();focusPreviousChild();
//                   //qDebug()<<focusWidget()->objectName();
//                   break;
//               }
//             }
//           case OK:
//             {
//                   if(watched!= theBtn[14])
//                        emit button->clicked();
//                   else
//                   {
//                       if(theBtn[13]->text().length()>0)
//                       {
//                           NumKeyBoard= theBtn[13]->text();
//                           emit changename2(NumKeyBoard);
//                       }
//                       this->deleteLater();
//                   }
//                   break;
//             }
//           case DOWN:
//             {
//               if(watched ==theBtn[8] || watched ==theBtn[9] ||watched ==theBtn[10] ||watched ==theBtn[11]||watched ==theBtn[12] )
//                   break;
//               else
//               {
//                    focusNextChild();focusNextChild();focusNextChild();focusNextChild();
//                    break;
//               }
//               break;
//             }
//           case LEFT:
//             {
//               if(watched !=theBtn[14])
//                   focusPreviousChild();
//                   break;
//             }
//           case RIGHT:
//             {
//               if(watched !=theBtn[12])
//                   focusNextChild();
//                   break;
//             }
//           case BACK:
//           {
//               this->parentWidget()->show();
//               this->close();
//               break;
//           }
//           case INIT:
//           {
////               if(thekeyboard_flag==1)//enter from expert menu
////                {
////                   QWidget *win = this;
////                   QWidget *win2 = win;
////                   win2 = win;
////                   win = win->parentWidget();
////                   win2->deleteLater();
////                   win2 = win;
////                   win = win->parentWidget();
////                   win2->deleteLater();
////                   QPushButton *btn = win->findChild<QPushButton *>("btn_Createdata");
////                   if(btn!=NULL)
////                       emit btn->clicked();
////                   break;
////                }
////               if(thekeyboard_flag==2)//enter from caliwea and caliwea_pm
////               {
////               QWidget *win = this;
////               QWidget *win2 = win;
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               QPushButton *btn = win->findChild<QPushButton *>("btn_Createdata");
////               if(btn!=NULL)
////                   emit btn->clicked();
////               break;
////               }
////               if(thekeyboard_flag==3)//enter from  flowcali
////               {
////               QWidget *win = this;
////               QWidget *win2 = win;
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               win2 = win;
////               win = win->parentWidget();
////               win2->deleteLater();
////               QPushButton *btn = win->findChild<QPushButton *>("btn_Createdata");
////               if(btn!=NULL)
////                   emit btn->clicked();
////               break;
////               }
//////               else   //enter from others ==0
//////               {
//////               QWidget *win = this;
//////               QWidget *win2 = win;
//////               win2 = win;
//////               win = win->parentWidget();
//////               win2->deleteLater();
//////               win2 = win;
//////               win = win->parentWidget();
//////               win2->deleteLater();
//////               win2 = win;
//////               win = win->parentWidget();
//////               win2->deleteLater();
//////               win2 = win;
//////               win = win->parentWidget();
//////               win2->deleteLater();
//////               QPushButton *btn = win->findChild<QPushButton *>("btn_Createdata");
//////               if(btn!=NULL)
//////                   emit btn->clicked();
//////               break;
//////               }

//           }
//            default:
//               break;
//           }
//        }
//        else if (event->type()==QEvent::FocusIn)     //然后再判断控件的具体事件 (这里指获得焦点事件)
//                  {
//                      QPushButton *focus_button = (QPushButton *)watched;
//                      focus_button->setStyleSheet("QPushButton{color:black;background-color: rgb(255, 255, 255);\
//                                                  border-radius:4px;  border: 2px groove blue; padding:1px 4px;\
//                                                 border-style: outset;}");
//                  }
//        else if (event->type()==QEvent::FocusOut)    // 这里指 lineEdit1 控件的失去焦点事件
//                 {
//                    QPushButton *focus_button = (QPushButton *)watched;
//                    focus_button->setStyleSheet("QPushButton{color:black;background-color: rgb(255, 255, 255);\
//                                                border-radius:4px;  border: 1px groove gray; padding:1px 4px;\
//                                               border-style: outset;}");
//                 }
//}
//}
